const Connection = `
type Connection {
    name: String!
    host: String
    port: Int
    username: String
    password: String
}

input ConnectionInput {
    name: String!
    host: String
    port: Int
    username: String
    password: String
}
`;

export default () => [Connection];

import dbms from '../../dbms';
const data = dbms.connection;

export const queryDefs = `
connections: [Connection]
connection(name: String!): Connection
`;

export const queries = {
    connections() {
        return data.load(true);
    },
    connection(_, {name}) {
        return data.get(name);
    }
};

export const mutationDefs = `
createConnection(connection: ConnectionInput): Connection
modifyConnection(name: String!, connection: ConnectionInput): Connection
removeConnection(name: String!) : Boolean
removeConnections: Boolean
`;

export const mutations = {
    createConnection(_, {connection}) {
        return data.create(connection);
    },
    modifyConnection(_, {name, connection}) {
        return data.modify(name, connection);
    },
    removeConnection(_, {name}) {
        return data.remove(name).then(() => true);
    },
    removeConnections() {
        return data.remove().then(() => true);
    }
};
